﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BottomCDEffect : MonoBehaviour
{
	public List<GameObject> showGoList = new List<GameObject>();

	public float maxTime;
	public float curTime;

	private int index = 0;
	private void Awake()
	{
		enabled = false;
		Hide();
	}
	private void Hide()
	{
		for (int i = 0; i < showGoList.Count; i++)
		{
			showGoList[i].SetActive(false);
		}
	}
	public void StartCD(float cd,float maxCd)
	{
		curTime = maxCd - cd;
		maxTime = maxCd;
		enabled = true; 
		index = 0;
		int a = GetIndex();
		for (int i = 0; i < showGoList.Count; i++)
		{
			showGoList[i].SetActive(i<a);
		}
	}
    int GetIndex()
	{
		int i = (int)(curTime / maxTime * showGoList.Count);

		if (i >= showGoList.Count)
			i = showGoList.Count;
		if (i < 0)
			i = 0;
		return i;
	}
    void Update()
    {
		if (curTime < maxTime)
		{
			curTime += Time.deltaTime;
			int i = GetIndex();
			if (index != i)
			{
				showGoList[i-1].SetActive(true);
				index = i;
			}
			if (curTime >= maxTime)
			{
				enabled = false;
			}
		}
    }
}
